from pulp import *

# 1. 建立问题
prob = LpProblem("Maximize_M", LpMaximize)

# 2. 建立变量 变量
x11 = LpVariable("x11", 0)
x12 = LpVariable("x12", 0)
x13 = LpVariable("x13", 0)
x14 = LpVariable("x14", 0)
x21 = LpVariable("x21", 0)
x22 = LpVariable("x22", 0)
x23 = LpVariable("x23", 0)
x24 = LpVariable("x24", 0)
x31 = LpVariable("x31", 0)
x32 = LpVariable("x32", 0)
x33 = LpVariable("x33", 0)
x34 = LpVariable("x34", 0)
kk = LpVariable("kk", 0)

# 3. 设置目标函数 目标函数
prob += (x11 + x21 + x31) * 3100 + (x12 + x22 + x32) * 3800 + (x13 + x23 + x33) * 3500 + (x14 + x24 + x34) * 2850

# 4. 施加约束 公式
prob += x11 + x12 + x13 + x14 <= 10
prob += x21 + x22 + x23 + x24 <= 16
prob += x31 + x32 + x33 + x34 <= 8

prob += 480 * x11 + 650 * x12 + 580 * x13 + 390 * x14 <= 6800
prob += 480 * x21 + 650 * x22 + 580 * x23 + 390 * x24 <= 8700
prob += 480 * x31 + 650 * x32 + 580 * x33 + 390 * x34 <= 5300

prob += (x11 + x12 + x13 + x14) / 10 == kk
prob += (x21 + x22 + x23 + x24) / 16 == kk
prob += (x31 + x32 + x33 + x34) / 8 == kk

prob += x11 + x21 + x31 <= 18
prob += x12 + x22 + x32 <= 15
prob += x13 + x23 + x33 <= 23
prob += x14 + x24 + x34 <= 12

# 5. 求解
prob.solve()

# 6. 打印求解状态
print("Status:", LpStatus[prob.status])

# 8. 打印最优解的目标函数值
print("z= ", value(prob.objective))

# 7. 打印出每个变量的最优值
for v in prob.variables():
    print(v.name, "=", v.varValue)
